<?php
/**
 * This file is part of the Jindai.
 * @copyright Copyright (c) 2019 All Rights Reserved.
 * @author jindai <jindai0305@gmail.com>
 */

namespace App\Models;

use App\Models\traits\FlagTrait;
use App\Models\traits\PublishTrait;
use App\Models\traits\SoftDeleteTrait;

/**
 * Class Tag
 * @package App\Models
 *
 * @property integer $id
 * @property string $name
 * @property array $tags
 * @property string $content
 * @property array $cover
 * @property integer $status
 * @property integer $created_at
 * @property integer $deleted_at
 * @property integer $flag
 *
 * @property-read Song $songs
 */
class SongMenu extends BaseModel
{
    use PublishTrait, SoftDeleteTrait, FlagTrait;

    protected $fillable = [
        'name', 'content', 'tags', 'status', 'cover', 'flag'
    ];

    const FLAG_DEFAULT = 0x1;

    const UPDATED_AT = null;

    /**
     * @inheritdoc
     */
    public function getTable()
    {
        return 'song_menus';
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function songs()
    {
        return $this->belongsToMany(Song::class, 'songables', 'menu_id', 'song_id');
    }

    /**
     * @inheritdoc
     */
    protected function appendCasts(): array
    {
        return [
            'tags' => 'array',
            'cover' => 'array',
        ];
    }

    public function isDefault()
    {
        return $this->hasFlag(self::FLAG_DEFAULT);
    }
}
